package com.bishe.demo.modules.hotel.hotel.dao;

import com.bishe.demo.modules.hotel.hotel.entity.Comment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface CommentDao {
    @Insert("insert into hotel_comment values(null,#{pid},#{detail},#{orderId})")
    @Options(useGeneratedKeys = true, keyProperty = "commentId", keyColumn = "comment_id")
    void insertComment(Comment comment);

    @Select("select * from hotel_comment where order_id=#{orderId}")
    @Results(id = "commentResult", value = {
            @Result(property = "commentId", column = "comment_id"),
            @Result(property = "comment", column = "comment_id", javaType = Comment.class,
                    one = @One(select = "com.bishe.demo.modules.hotel.hotel.dao.CommentDao.getCommentByPid"))
    })
    Comment getCommentByOrderId(int orderId);

    @Select("select * from hotel_comment where pid=#{comment_id}")
    Comment getCommentByPid(int pid);
}
